package com.zz.framework.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Path
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView

/**
 * Copyright © 2025 zhun All rights reserved.
 * Created by ZhaoZhun on 2025/3/18 14:09.
 * @author: ZhaoZhun 1820022519@qq.com
 * @version: V1.0
 */
class SkewedImageView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {

    private val path = Path()
    override fun onDraw(canvas: Canvas) {
        val width = width.toFloat()
        val height = height.toFloat()
        path.reset()
        path.moveTo(0f, 0f)  // 左上角偏移
        path.lineTo(width, 0f)  // 左上角偏移
        path.lineTo(width * 0.75f, height)          // 右上角
        path.lineTo(0f, height)      // 右下角
        path.lineTo(0f, 0f)  // 左下角偏移
        path.close()
        canvas.clipPath(path)  // 裁剪
        super.onDraw(canvas)
    }
}